Kuo["admin/gateway"] = {
    OFF:["关闭","正常"],
    TYPE:['前置网关','登陆网关','游戏网关'],
    RENQI:['良好','热门','火爆','拥挤','测试'],
    init(){

        Kuo['admin/gateway'].get();

        var xxx = '<option value="">全部类型</option>';
        for(var n in Kuo["admin/gateway"].TYPE){
            xxx += '<option value="'+n+'">'+ Kuo["admin/gateway"].TYPE[n]+'</option>';
        }
        $("."+$class+"saixuan [name='so_type']" ).html(xxx);
        layui.form.render("select");
            

    },get(){

        $("#LAY_app_body ."+$class).html('<style>.'+$class+' .color0{color:#000;} .'+$class+' .color1{color:green;}.'+$class+' .color2{color:Orange;}.'+$class+' .color3{color:red;}.'+$class+' .color4{color:#aaa;}</style><div class="layui-fluid"><div class="layui-card"><div class="layui-card-body" style="padding: 15px;"><div class="'+$class+'saixuan" style="display:none;margin-bottom:8px;"><form name="form" class="layui-form"> <div class="layui-inline" style="width:128px;"> <select name="so_type" class="so_var"></select> </div>  <div class="layui-inline" style="width:88px;"> <input class="layui-input so_var" name="so_id" autocomplete="off" placeholder="网关id"> </div> <div class="layui-inline" style="width:88px;"> <input class="layui-input so_var" name="so_name" autocomplete="off" placeholder="网关名字"> </div> <input class="layui-input so_var"  value="shuaxin" name="so_shuaxin" type="hidden" autocomplete="off">  <button class="layui-btn" lay-event="sousuo" lay-submit lay-filter="tijiao'+$class+'">搜索</button>   </form> </div><table class="layui-hide" id="gateway'+$class+'" lay-filter="gateway'+$class+'"></table></div></div></div>');
        layui.table.render({
        elem: '#gateway'+$class
        ,url: PLUG+'gateway'+FENGE+TOKEN+FENGE+'get'
        ,toolbar:'<div><a class="layui-btn layui-btn-normal" lay-event="add"><i class="layui-icon layui-icon-addition"></i>新增</a> <a class="layui-btn " lay-event="refresh"><i class="layui-icon layui-icon-refresh-3"></i> 刷新</a> <a class="layui-btn layui-btn-danger" lay-event="saixuan"><i class="layui-icon layui-icon-search"></i>筛选</a>  </div>'
       ,cols: [[
            {field:'id', title: '网关ID', width:80,  fixed: true}
            ,{field:'name', title: '网关名字'}
            ,{field:'type', title: '类型',templet  :function(d){
                return '<span class="color'+d.type+'">'+Kuo['admin/gateway'].TYPE[d.type]+'</span>';
            }}
            
            ,{field:'tcpip', title: '网关信息',templet  :function(d){

                return d.tcpip+':'+d.tcpprot;
            }}

            ,{field:'udpip', title: '服务信息',templet  :function(d){

                return d.udpip+':'+d.udpprot;
            }},{field:'off', title: '状态',templet  :function(d){

                return '<span class="color'+d.off+'">'+Kuo['admin/gateway'].OFF[d.off]+'</span>';
            }}
            ,{field:'renqi', title: '人气',templet  :function(d){

                return '<span class="color'+d.renqi+'">'+Kuo['admin/gateway'].RENQI[d.renqi]+'</span>';
            }} ,{field:'hit', title: '链接数'}
            
            ,{title:'操作', templet  :function(d){
                return '<a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a><a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>';
            }}
        ]]
        ,limit:20
        
        ,page: true
        ,done: function(data, curr, count){
            if(data.token && data.token != ""){
                TOKEN = data.token;
            }
            
        
        }
        });

        layui.table.on('toolbar(gateway'+$class+')', function(obj){
            if(obj.event === 'add'){
                Kuo['admin/gateway'].add();
            }else if(obj.event === 'refresh'){
                layer.closeAll();
                Kuo['admin/gateway'].init();
            }else if(obj.event === 'saixuan'){
                $("."+$class+"saixuan").toggle();
                $('.tongjijine'+$class).hide();
  
              }
        });

        layui.table.on('tool(gateway'+$class+')', function(obj){
            if(obj.event === 'del'){
                layer.confirm('真的要删除吗?', function(index){
                Kuo['admin/gateway'].del(obj);
                layer.close(index);
                });
            }else if(obj.event === 'edit'){
                Kuo['admin/gateway'].edit(obj);
            }
        });

        layui.form.on('submit(tijiao'+$class+')', function(formdata){
            formdata = formdata.field;
            var zuhesou = {};
                $('.so_var').each(function(i,v){
                  if($(v).val() != ""){
                    zuhesou[ $(v).attr('name').replace('so_','')  ] = $(v).val();
                  }
                  
                });
              
         
              
            layui.table.reload('gateway'+$class, {
              page: {
                curr: 1 //重新从第 1 页开始
              },
              url: PLUG+'gateway'+FENGE+TOKEN+FENGE+'get'
              
              ,where: zuhesou //设定异步数据接口的额外参数
              
            });
              
  
            return false;
          });
        layui.table.render();

    },edit(OBJ,diercai){
        if(diercai != "add"){
            diercai = "put";
            var title ="编辑网关";
        }else{
            var title ="新建网关";
        }

    
        var D = OBJ.data;
        var BIAO = [];
        var html ='<form name="form" id="form" class="layui-form '+$class+'">';
       
        BIAO = [
            
            'id($$)网关id($$)hidden($$)($$)网关id($$)'+D.id,
            'name($$)网关名字($$)text($$)($$)网关名字($$)' + D.name,
            'wslink($$)网关url($$)text($$)($$)网关url($$)' + D.wslink,
            
            'type($$)网关类型($$)select($$)($$)Kuo["admin/gateway"].TYPE($$)' + D.type,
            'tcpip($$)网关ip($$)text($$)($$)网关ip($$)' + D.tcpip,
            'tcpprot($$)网关端口($$)text($$)($$)网关端口($$)' + D.tcpprot,
            'udpip($$)服务ip($$)text($$)($$)服务ip($$)' + D.udpip,
            'udpprot($$)服务端口($$)text($$)($$)服务端口($$)' + D.udpprot,
            'off($$)状态($$)select($$)($$)Kuo["admin/gateway"].OFF($$)' + D.off,
            'renqi($$)火爆状态($$)select($$)($$)Kuo["admin/gateway"].RENQI($$)' + D.renqi,
            'hit($$)链接人数($$)text($$)($$)链接人数($$)' + D.hit,
            'maxnum($$)最大人数($$)text($$)($$)最大人数($$)' + D.maxnum
       
        ];
        for(var z in BIAO){
            html+=jsfrom(BIAO[z]);
        }



        html+=jsfrom('ff'+$class+'($$)($$)submit($$)($$)layer.close(OPID);Kuo[\'admin/features\'].init()($$)提交($$)tijiao');
        html+="</form>";
        
        OPID = layer.open({
          type: 1,
          zIndex:10000,
          title:title,
          area:['100%', '100%'],
          fixed: true, 
          maxmin: true,
          content: html,
          success: function(layero, index){
            
          }
        });



        layui.form.on('submit(ff'+$class+')', function(formdata){
            formdata = formdata.field;
            formdata.Format = 'json';
            $.post(PLUG+"gateway"+FENGE+TOKEN+FENGE+diercai,formdata,function(data){
                if(data.token && data.token != ""){
                    TOKEN = data.token;
                }
                if(data.code == 99){
                    layer.close(OPID);
                    layer.msg("请登陆",{offset: 'c',time: 2000},function(){
                        loadjs("home");
                    });
                }else if(data.code == 1){

                    if(diercai == "put"){
                        OBJ.update(data.data);
                        layer.close(OPID);
                    }else{
                        Kuo['admin/gateway'].get();
                        layer.close(OPID);
                    }
                    

                }else{
                    
                    layer.msg(data.msg,{zIndex:99999,offset: 'c',time: 2000});
                }
            });

           

            return false;
        });

        layui.form.render();
    },add(){
        Kuo['admin/gateway'].edit({
            data:
            {"wslink":"","id":0,"name":"","type":"0","tcpip":"","tcpprot":"0","udpip":"","udpprot":"0","off":"0","renqi":"0","hit":"0","maxnum":"0"}
        },'add');
    },del(OBJ){
        var fromdata = {
            Format:'json',
            id:OBJ.data.id
            };
        $.post(PLUG+"gateway"+FENGE+TOKEN+FENGE+'del',fromdata,function(data){
            if(data.token && data.token != ""){
                TOKEN = data.token;
            }
            if(data.code == 99){
                layer.msg("请登陆",{offset: 'c',time: 2000},function(){
                loadjs("home");
                });
            }else if(data.code == 1){
                OBJ.del();
            }else{
                layer.msg(data.msg,{zIndex:99999,offset: 'c',time: 2000});
            }

        });

    }
}
Kuo['admin/gateway'].init();